﻿<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>gymMain</title>
<link href="../css/style.css" rel="stylesheet" type="text/css"
	media="all" />
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--slider-->
<link rel="stylesheet" href="../css/flexslider.css" type="text/css"
	media="all" />
<!-- jQuery -->
<!-- FlexSlider -->

<link rel="stylesheet" type="text/css"
	href="../bootstrap/bootstrap.4.1.0.css">
<script src="../bootstrap/jquery.3.2.1.min.js"></script>
<script src="../bootstrap/popper.12.5.min.js"></script>
<script src="../bootstrap/bootstrap.4.1.0.min.js"></script>
<script src="/layui/layer/layer.js"></script>
<script src="../vue/Vue.js"></script>
<script src="../vue/axios.js"></script>
<script type="text/javascript">
	$(function() {
		$("#header").load("../zlz/header.html");
		
	})
</script>
</head>
<body>
	<div id="app">
		<div id="header"></div>
		<div id="app2" class="container">
		<!--  <div><label>课程名称:</label><input type="text" v-model="coursename"></div>
		<div><label>价格:&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</label><input type="number" v-model="price"></div>
		<div><button class="btn btn-outline-info" @click="add">添加</button></div><br>  -->
		签约教练：<select v-model="theCoach" @change="free(theCoach)">
			<option v-for="coa in coaches" :value="coa.userId">{{coa.coach.nickname}}</option>
		</select>
		<!-- 选中了{{theCoach}}  -->
		选择日期：<select @change="getClazz(theDay)" v-model="theDay">
			<option v-for="day in freeDay" :value="day">{{day.recentday}}</option>
		</select> 选择哪节课：<select v-model="theClazz">
			<option v-for="clazz in freeTime" :value="clazz">{{clazz}}</option>
		</select> 选择课程： <select v-model="courseId">
			<option v-for="course in courses" :value="course.id">{{course.courseName}}</option>
		</select> 选择流派： <select v-model="styleId">
			<option v-for="style in styles" :value="style.id">{{style.styleName}}</option>
		</select><br>
		<button @click="submit()"  class="btn btn-outline-info">排课</button>
		{{message}}
		<br>
		
		<hr style="width=100%">
		已排课程：<table class="table table-bordered">
			<thead>
				<tr v-if="chcourses.length!=0">
					<th>选课id</th>
					
					<th>日期</th>
					<th>上课时段</th>
				</tr>
				
			</thead>
			<tbody>
				
				<tr v-for="cou in chcourses" v-if="cou !=null">
					<td>{{cou.id}}</td> 
					<td>{{cou.date}}</td>
					<td>
						{{cou.time}}
					</td>
					
					
				</tr>
			</tbody>
			</div>
		</table>
		<div class="footer">
			<div class="wrap">
				<div class="section group">
					<div class="col_1_of_footer span_1_of_footer">
						<div class="location">
							<h3>地址</h3>
							<ul>
								<li>1-22-003-55,</li>
								<li>四川省成都市</li>
								<li>火车南站蜗牛hifit</li>
								<li>CHINA</li>
							</ul>
						</div>
					</div>
					<div class="col_1_of_footer span_1_of_footer">
						<h3>信息</h3>
						<p>hifit健身，创建于2005年，立足长三角，辐射全中国！专注健身15年，已发展成为中国大型直营健身连锁领跑者。截至2018年7月，hifit健身已拥有400+家签约及开业的直营门店。</p>
					</div>
					<div class="col_1_of_footer span_1_of_footer">
						<h3>品牌简介</h3>
						<div class="Testimonials_desc">
							<p>
								<span class="up"></span>hifit健身，立足长三角，专注健身14年，拥有400+家签约及开业的直营门店。累计发展会员人数300余万，每年新增约80万会员，每天约30万会员在全国各分店享受专业健身服务。<span
									class="down"><img src="" alt=""></span>
							</p>

						</div>
					</div>
					<div class="col_1_of_footer span_1_of_footer">
						<h3>联系我们</h3>
						<ul class="address">
							<li>蜗牛科技</li>
							<li><span>电话:</span> +86 132123456789</li>
							<li><span>座机:</span> +32 132 74895</li>
							<li><span>传真:</span> +69 320 832479</li>
						</ul>
					</div>
					<div class="clear"></div>
				</div>
			</div>
			<div class="copy-right">
				<div class="wrap">

					<p class="copy">&copy; Copyright &copy; 2020.Cyh All rights
						reserved.</p>

				</div>
			</div>
		</div>
	</div>

</body>
<script type="text/javascript">

var vm=new Vue({
    el:"#app",
    data:{
        coaches:[],
        styles:[],
        courses:[],
        chcourses:[],
        theCoach:"",
        theDay:"",
       freeDay:[],
       freeTime:[],
       courseId:"",
       styleId:"",
       theClazz:"",
       message:"",
       coursename:"", //添加add方法
		price:"",
       
    },
    mounted(){
    	
        axios.get("/gymInfo/mySginCoaches")
            .then(res => {
                //console.info(res.data);
                this.coaches = res.data;
            });
        
        axios.get("/gymInfo/allCoursesByGymId")
            .then(res => {
                //console.info(res.data);
                this.chcourses = res.data;
            });
        axios.get("/gymInfo/allStyles")
        .then(res => {
            //console.info(res.data);
            this.styles = res.data;
        });
        axios.get("/gymInfo/allCourses")
        .then(res => {
            //console.info(res.data);
            this.courses = res.data;
        });
    },
    methods:{
    	flush(){
    		 axios.get("/gymInfo/allCoursesByGymId")
             .then(res => {
                 //console.info(res.data);
                 this.chcourses = res.data;
             });
    		
    	},
    	add(){
			axios.get("/course/add?name="+this.coursename+"&price="+this.price).then( res=> {
				if(res.data.code==1){
					this.coursename = "";
					this.price = "";
					layer.alert("课程添加成功");
					flush();
				}else if(res.data.code==2){
					layer.alert("系统维护中，请稍后再试");
				}else if(res.data.code==3){
					layer.alert("您已添加过该课程，请勿重复添加!")
					this.coursename = "";
				}
			})
		},
        free(theCoach){
            //先请求，后台先归还，后台成功了，前台才应该删除数据
            var params = new URLSearchParams();
            params.append("id",vm.theCoach);
            axios.post("/gymInfo/freeDayByCoachId",params)
                .then(res => {
                	console.info(res.data)
                	this.freeDay=res.data; 
                })

        },
        getClazz(theDay){
            //先请求，后台先归还，后台成功了，前台才应该删除数据
            var params = new URLSearchParams();
            params.append("freeSum",theDay.freeSum);
            axios.post("/gymInfo/getFreeSumArray",params)
                .then(res => {
                	console.info(res.data)
                	this.freeTime=res.data; 
                })

        },
        submit(){
        
            var params = new URLSearchParams();
            params.append("userIdCoach",vm.theCoach);
            params.append("courseId",vm.courseId);
            params.append("styleId",vm.styleId);
            params.append("date",vm.theDay.recentday);
            params.append("time",vm.theClazz);
            axios.post("/gymInfo/arrangeCourse",params)
                .then(res => {
                	console.info(res.data)
                	if(res.data==1){
                		this.message="排课成功";
                	}else{
                		this.message="选课失败，重新再试试";
                	}
                })
        	
        }

    }
});
	</script>

</html>



